package impl

import (
	"adam2/internal/vo"
	pConstants "anubis-framework/pkg/constants"
	pDomain "anubis-framework/pkg/domain"
	"anubis-framework/pkg/util"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

type ModelTopConceptBoardIndexDetailControllerImpl struct {
	*BaseControllerImpl
}

// 获取ModelTopConceptBoardIndexDetailControllerImpl
func GetModelTopConceptBoardIndexDetailControllerImpl() *ModelTopConceptBoardIndexDetailControllerImpl {
	return &ModelTopConceptBoardIndexDetailControllerImpl{GetBaseControllerImpl()}
}

// 分页显示
func (_modelTopConceptBoardIndexDetailControllerImpl *ModelTopConceptBoardIndexDetailControllerImpl) Page(c *gin.Context) {
	// 转换参数
	var pageConceptBoardIndexVo *vo.PageConceptBoardIndexVo = &vo.PageConceptBoardIndexVo{}
	c.BindJSON(pageConceptBoardIndexVo)

	// 参数验证：参数pageNo和pageSize不能为空
	if pageConceptBoardIndexVo.PageNo == 0 || pageConceptBoardIndexVo.PageSize == 0 {
		var apiResult *pDomain.ApiResult = &pDomain.ApiResult{}
		apiResult.Code = pConstants.OPERATION_FAIL_CODE
		apiResult.Message = "参数pageNo和pageSize不能为空"
		apiResult.Success = false

		c.JSON(http.StatusBadRequest, *apiResult)
		return
	}

	// 参数验证：参数transactionDate不能为空
	if pageConceptBoardIndexVo.TransactionDate == "" {
		var apiResult *pDomain.ApiResult = &pDomain.ApiResult{}
		apiResult.Code = pConstants.OPERATION_FAIL_CODE
		apiResult.Message = "参数transactionDate不能为空"
		apiResult.Success = false

		c.JSON(http.StatusBadRequest, *apiResult)
		return
	}

	// 分页
	var transactionDate time.Time = util.StringToDate(pageConceptBoardIndexVo.TransactionDate)
	var serviceResult *pDomain.ServiceResult = _modelTopConceptBoardIndexDetailControllerImpl._modelTopConceptBoardIndexDetailServiceImpl.Page(pageConceptBoardIndexVo.OrderByColumnArray, transactionDate, pageConceptBoardIndexVo.PageNo, pageConceptBoardIndexVo.PageSize)
	var code, apiResult = util.ServiceResultToApiResult(serviceResult)
	c.JSON(code, *apiResult)
	return
}
